﻿namespace IBTrader.Indicator.CandleStick
{
    using IBTrader.Charts;

    /// <summary>
    /// On Balance Volume (OBV) measures buying and selling pressure as a cumulative indicator that adds volume on up days and subtracts volume on down days. 
    /// To predict price movements or use OBV to confirm price trends.
    /// </summary>
    class OBV : BaseVolume
    {
        private int up = 0;
        internal OBV(Worker worker, int interval = 60, int pinterval = 12) : base(worker, 1, interval, pinterval) { }
        protected override void Add(object _, Item item)
        {
            var last = (this as ILast).Last;
            if (item.Price > last.Price) up = 1;
            if (item.Price < last.Price) up = -1;
            Prices.Add(item.Volume * up);
            OnHit(item.CloseLine, Prices.Sum);
        }
    }
}